package oop;

import java.util.Calendar;
import java.util.Date;

/**
 * @author hanjian
 */
public class Person {
    private Date birth;

    public int getAge() {
        if (this.birth == null) {
            return -1;
        }

        Calendar nowCalendar = Calendar.getInstance();
        nowCalendar.setTime(new Date());
        Calendar birthCalendar = Calendar.getInstance();
        birthCalendar.setTime(this.birth);
        return nowCalendar.get(Calendar.YEAR) - birthCalendar.get(Calendar.YEAR);
    }

    public void setBirth(Date birth) {
        this.birth = birth;
    }

    public Date getBirth() {
        return this.birth;
    }

}
